package com.gzz.orchid.context.application.rbac.impl;

import com.gzz.orchid.common.core.tuple.TreeNode;
import com.gzz.orchid.context.application.rbac.IModuleHandler;
import com.gzz.orchid.context.application.rbac.convert.ModuleConverter;
import com.gzz.orchid.context.application.rbac.convert.RbacAssembler;
import com.gzz.orchid.context.application.rbac.pojo.ModuleDto;
import com.gzz.orchid.context.application.rbac.pojo.ModuleVo;
import com.gzz.orchid.context.application.rbac.queries.ModuleQuery;
import com.gzz.orchid.context.infrastructure.persistence.entity.sys.SysModulePo;
import com.gzz.orchid.context.infrastructure.persistence.mapper.sys.SysModuleMapper;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Optional;

/**
 * @author higmd
 */
@Slf4j
@Service
@RequiredArgsConstructor
public class ModuleHandler implements IModuleHandler {
    private final SysModuleMapper mapper;

    @Override
    public List<ModuleDto> listByPager(ModuleQuery query) {
        //QueryWrapper queryWrapper = new QueryWrapper();
        List<ModuleDto> dtoList = null; //mapper.paginateAs(1, 100, queryWrapper, ModuleDto.class);
        return dtoList;
    }

    @Override
    public List<ModuleDto> list(ModuleQuery query) {
        List<SysModulePo> modulePos = null; //mapper.selectAll();
        return RbacAssembler.mapModuleTreeDto(modulePos, 0L);
    }

    @Override
    public ModuleVo detail(Long id) {
        SysModulePo po = null;
        //mapper.selectOneById(id);
        return Optional.ofNullable(po)
                .map(ModuleConverter.INSTANCE::mapVo)
                .orElse(null);
    }

    @Override
    public List<TreeNode<Long>> options() {
        List<SysModulePo> modulePos = null;
        //mapper.selectAll();
        return RbacAssembler
                .mapModuleTreeOptions(modulePos, 0L);
    }
}
